package com.qef.com.mmovie.mvp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qef.com.mmovie.App;
import com.qef.com.mmovie.R;
import com.qef.com.mmovie.base.BaseRecycerViewAdapter;
import com.qef.com.mmovie.entity.DataBean;
import com.qef.com.mmovie.entity.VideoTopEntity.DataEntity;
import com.qef.com.mmovie.img.ImageLoader;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

import static android.R.attr.data;

/**
 * Created by guangjiego on 2017/3/24.
 */

public class VideoTopAdapter extends BaseRecycerViewAdapter<DataEntity.ResEntity, RecyclerView.ViewHolder> {
    public LayoutInflater inflater;
    public OnItemClickListener onItemClickListener;

    public VideoTopAdapter(Context context, List<DataEntity.ResEntity> list) {
        super(context, list);

    }

    @Override
    public RecyclerView.ViewHolder getCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_video_top, null);
        return new MyHolder(view);
    }

    @Override
    public void getBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        DataEntity.ResEntity dataBean = list.get(position);
        MyHolder myHolder = (MyHolder) holder;
        Glide.with(App.getInstance()).load(dataBean.getI()).into(myHolder.imageView);
        myHolder.jcVideoPlayer.release();
        myHolder.jcVideoPlayer.setVisibility(View.GONE);
        myHolder.ivPlay.setVisibility(View.VISIBLE);
        myHolder.ivPlay.setOnClickListener(v -> onItemClickListener.
                onItemClick(position, v, myHolder));
        String t = dataBean.getT();
        myHolder.textView.setText(dataBean.getT());
        myHolder.tvGood.setText(String.valueOf(dataBean.getZan_num()));
    }


    public class MyHolder extends RecyclerView.ViewHolder {
        public JCVideoPlayerStandard jcVideoPlayer;
        public ImageView imageView;
        public ImageView ivPlay;
        public TextView textView;
        public RelativeLayout rl_video_info;
        TextView tvGood;

        public MyHolder(View itemView) {
            super(itemView);
            jcVideoPlayer = ((JCVideoPlayerStandard) itemView.findViewById(R.id.jc_video));
            imageView = (ImageView) itemView.findViewById(R.id.video_img);
            ivPlay = (ImageView) itemView.findViewById(R.id.fab);
            textView = (TextView) itemView.findViewById(R.id.titlex);
            rl_video_info = (RelativeLayout) itemView.findViewById(R.id.rl_video_info);
            tvGood = (TextView) itemView.findViewById(R.id.tv_goodnum);
        }
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener itemClickListener) {
        super.setOnItemClickListener(itemClickListener);
        this.onItemClickListener = itemClickListener;
    }
}
